package java8Com.chap3;

import vo.Apple;

import java.util.function.Function;
import java.util.function.Predicate;

/**
 * 谓词复合
 */
public class predicateComs {

    //negate
    public static void test1() {
        Predicate<Apple> readApple = (e) -> e.getColor().equals("read");

        Predicate<Apple> negate = readApple.negate();
        System.out.println(negate.test(new Apple("gree")));
        System.out.println(readApple.test(new Apple("gree")));
    }

    //and or
    public static void test2() {
        Predicate<Apple> readApple = (e) -> e.getColor().equals("read");
        Predicate<Apple> redAndHeavyApple = readApple.and(a -> a.getWeight() > 150)
                .or(a -> "green".equals(a.getColor()));
    }

    public static void test3() {
        Function<Integer, Integer> f=x -> x +1;
        Function<Integer, Integer> p=x -> x *2;
        Function<Integer, Integer> function = f.andThen(p);
        System.out.println(function.apply(1));

        Function<Integer, Integer> compose = f.compose(p);
        System.out.println(compose.apply(1));
    }



        public static void main(String[] args) {
        test3();
    }
}
